package cn.itsource.pethome.org.service.impl;

import cn.itsource.pethome.basic.service.impl.BaseServiceImpl;
import cn.itsource.pethome.org.domain.Employee;
import cn.itsource.pethome.org.domain.Shop;
import cn.itsource.pethome.org.mapper.EmployeeMapper;
import cn.itsource.pethome.org.mapper.ShopMapper;
import cn.itsource.pethome.org.service.IEmployeeServive;
import cn.itsource.pethome.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {
    @Autowired
    IEmployeeServive employeeServive;
    @Autowired
    EmployeeMapper employeeMapper;
    @Autowired
    ShopMapper shopMapper;

    @Override
    public void save(Shop shop) {
        //获取门店管理人员即前台传入的admin
        Employee admin = shop.getAdmin();
        //添加店长
        employeeServive.save(admin);
        //添加门店
        shopMapper.save(shop);
        //设置admin的shop_id字段
        admin.setShop(shop);
        //修改admin的shop_id
        employeeMapper.update(admin);


    }
}
